//
//  SingerDetailViewController.m
//  LuckyRadio
//
//  Created by Mr、J on 15/11/21.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "SingerDetailViewController.h"
#import "SingerDetailModel.h"
#import "CustomerNetworking.h"
#import "SingerDetailTableViewCell.h"
#import "SingerInforViewController.h"
#import <MBProgressHUD.h>

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH_PRO(X) (X)*(SCREEN_WIDTH/375)

#define HEIGHT_PRO(Y) (Y)*(SCREEN_HEIGHT/667)

@interface SingerDetailViewController ()<UITableViewDataSource, UITableViewDelegate, MBProgressHUDDelegate>

@property (nonatomic, retain) UITableView *tableView;

@property (nonatomic, retain) NSMutableArray *dataArray;

@property (nonatomic, retain) NSMutableArray *listArray;

@property (nonatomic, retain) MBProgressHUD *HUD;

@property (nonatomic, retain) UIView *zhanView;

@end

@implementation SingerDetailViewController
- (void)dealloc
{
    [_zhanView release];
    [_HUD release];
    [_listArray release];
    [_dataArray release];
    [_tableView release];
    [_ID release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.dataArray = [NSMutableArray array];
    self.listArray = [NSMutableArray array];
    [self createSubViews];
    [self loadData];
}

-(void)createSubViews
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - HEIGHT_PRO(64)) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [_tableView release];
    
    self.zhanView = [[UIView alloc] initWithFrame:self.view.bounds];
    self.zhanView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.zhanView];
    [_zhanView release];
}

-(void)loadData
{
    self.HUD = [[MBProgressHUD showHUDAddedTo:self.view animated:YES] retain];
    self.HUD.delegate = self;
    
    self.HUD.labelText = @"正在进行加载~";
    
    [CustomerNetworking customerWithURL:[NSString stringWithFormat:@"http://v1.ard.tj.itlily.com/ttpod?a=getnewttpod&id=%@&size=1000&page=1&app=ttpod&v=v8.1.1.2015110616&user_id=0&mid=iPhone5S&f=f234&s=s310&imsi=&hid=&splus=9.1&active=1&net=2&openudid=e97c1f17f916efa173065a10152c7506e65b60f7&idfa=5FBD2BF5-1484-4C9B-A138-4D9CE22EADB5&utdid=VkKezJUW5SwDAGga0yzrZnyO&alf=700606&bundle_id=com.ttpod.music&latitude=38.89678887106898&longtitude=121.5286360014996", _ID] andParamer:nil andBlock:^(id response) {
        NSLog(@"%@",response);
        for (NSDictionary *dic in [response objectForKey:@"data"]) {
            SingerDetailModel *singerDetailModel = [SingerDetailModel modelWithDictionary:dic];
            [self.dataArray addObject:singerDetailModel];
        }
        
        
        [self.tableView reloadData];
        [self.HUD hide:YES];
        [self.zhanView removeFromSuperview];
        
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return HEIGHT_PRO(100);
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SingerDetailModel *singerDetailModel = _dataArray[indexPath.row];
    SingerDetailTableViewCell *cell = [SingerDetailTableViewCell singerDetailTableViewCellWith:tableView];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.singerDetailModel = singerDetailModel;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    SingerInforViewController *singerInfor = [SingerInforViewController new];
    SingerDetailModel *singerDetailModel = _dataArray[indexPath.row];
    singerInfor.singerDetailModel = singerDetailModel;
    [self presentViewController:singerInfor animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
